package metuan_;

import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

/**
 *
 */
public class Main {
    private static int n;
    private static Long[] a;
    private static Long ans=0L;
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        n=scanner.nextInt();
        a=new Long[n];
        for(int i=0;i<n;++i){
            a[i]=scanner.nextLong();
        }
        Arrays.sort(a);
        for(int i=0;i<n-1;++i){
            ans+=(Math.abs(a[i]-a[i+1]));
        }
        System.out.println(ans);
    }
}
